import DAL from './dal.js';
import util from './util.js'
/**
 * 查询A36 社会关系表的方法
 */
class A36DAL{
	constructor(){
		this.init();
	};
	
	init(){
		this.db = new DAL();
		this.util = new util();
	};
	
	//在js中 数组和json应该是一样的，数组可以当作key是0 1 2 的json
	toCanRead(originalJsonInfoArray){
		//console.log(originalJsonInfoArray)
		let canReadArray = new Array();
		for(let key in originalJsonInfoArray){
	
			let originalJson = originalJsonInfoArray[key];//这个才是真正的json
			
			let temp = {};
			for(let item in originalJson){
			
				if(originalJson[item]==null||originalJson[item]=='null'){
                    originalJson[item]='';
                }
				
				if(this.util.A36Dictionary[item]){
					if (originalJson[item]){
						temp[this.util.A36Dictionary[item]] = originalJson[item].toString().trim()
					}
					else{
						temp[this.util.A36Dictionary[item]] = '';
					}

				}
				
			}
			canReadArray.push(temp)
		}
		return canReadArray;
	}
	
	// function strToJson(str){
	//     var json = eval('(' + str + ')');
	//          return json;
	// }
	
	/**
	 * 1.通过家属模糊姓名查到干部ID
	 * @param {Object} familyName jishu 
	 * 返回干部ID数组，很可能有同名家属，所以有可能查出好几个干部
	 * json数据项：A0000
	 */
	async SelectPersionIDByFamilyName(familyName){
		let temp =  this.toCanRead(await this.db.SelectDataFieldArrayFromDB ('A36','DISTINCT A0000',`WHERE
								(	A36.A3601 LIKE \'%${familyName}%\' OR
									A36.X0001 LIKE \'%${familyName}%\' OR
									A36.X0002 LIKE \'%${familyName}%\' ) `))
        return temp;
	}
	
	/**
	 * 通过人员ID查询其家属,返回家属数组
	 * 返回A3601,A3604A,A3607,A3627,A3611,SORTID,CadreID,IsInResumeFile
	 */
	async SelectFamilyArrayByPersionID(persionID){
		

		return  this.toCanRead(await this.db.SelectDataFieldArrayFromDB ('A36','A3601,A3604A,A3607,A3627,A3611,SORTID,CadreID,IsInResumeFile',`WHERE
									A36.A0000 = \'${persionID}\'  order BY SORTID `))

	}
}
export default A36DAL;